package com.proton.carepatchtemp.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.WindowManager;
import android.widget.ImageView;

import com.proton.carepatchtemp.R;
import com.proton.carepatchtemp.base.BaseActivity;
import com.proton.carepatchtemp.fragment.UseDirection1Fragment;
import com.proton.carepatchtemp.fragment.UseDirection2Fragment;
import com.proton.carepatchtemp.fragment.UseDirection3Fragment;
import com.proton.carepatchtemp.utils.eventbus.MainEvent;

import java.util.ArrayList;
import java.util.List;

public class UseDirectionActivity extends BaseActivity {

    private ImageView mIvClose;
    private ViewPager mVpUseDirectionContainer;
    private List<Fragment> mFragmentList = new ArrayList<>();

    @Override
    public void dealEvent(MainEvent event) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       /*set it to be full screen*/
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_use_direction);
        initView();
        initViewPager();
        setListener();
    }

    private void initViewPager() {
        mFragmentList.add(UseDirection1Fragment.newInstance(null, null));
        mFragmentList.add(UseDirection2Fragment.newInstance());
        mFragmentList.add(UseDirection3Fragment.newInstance());
        mVpUseDirectionContainer.setAdapter(new UseViewPagerAdapter(getSupportFragmentManager(), mFragmentList));
    }

    @Override
    protected void setListener() {
        mIvClose.setOnClickListener(v -> {
            finish();
        });
    }

    private void initView() {
        mIvClose = findViewById(R.id.iv_close);
        mVpUseDirectionContainer = findViewById(R.id.vp_use_direction_container);
    }

    @Override
    public void onEventMainThread(MainEvent event) {

    }

    private class UseViewPagerAdapter extends FragmentStatePagerAdapter {
        private List<Fragment> mFragments;

        public UseViewPagerAdapter(FragmentManager fm, List<Fragment> realTimeItemFragments) {
            super(fm);
            this.mFragments = realTimeItemFragments;
        }
        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getItemPosition(Object object) {
            return PagerAdapter.POSITION_NONE;
        }

        @Override
        public int getCount() {
            return null == mFragments ? 0 : mFragments.size();
        }
    }
}
